{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [],
   "source": [
    "import numpy as np"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "matrix_one=np.array([[1,2],[3,4]])\n",
    "matrix_two=np.array([[5,6],[7,8]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5, 12],\n",
       "       [21, 32]])"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对应元素相乘\n",
    "#[1*5],[2*6]\n",
    "#[3*7],[4*8]\n",
    "matrix_one*matrix_two"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5, 12],\n",
       "       [21, 32]])"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#对应元素相乘\n",
    "#[1*5],[2*6]\n",
    "#[3*7],[4*8]\n",
    "np.multiply(matrix_one,matrix_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[19, 22],\n",
       "       [43, 50]])"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#矩阵乘积,行与列乘积的和\n",
    "#[1*5+2*7],[1*6+2*8]\n",
    "#[3*5+4*7],[3*6+4*8]\n",
    "np.matmul(matrix_one,matrix_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[19, 22],\n",
       "       [43, 50]])"
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#矩阵乘积,行与列乘积的和\n",
    "#[1*5+2*7],[1*6+2*8]\n",
    "#[3*5+4*7],[3*6+4*8]\n",
    "np.dot(matrix_one,matrix_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[17, 23],\n",
       "       [39, 53]])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#矩阵内积，行与行乘积的和\n",
    "#[1*5+2*6],[1*7+2*8]\n",
    "#[3*5+4*6],[3*7+4*8]\n",
    "np.inner(matrix_one,matrix_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[ 5,  6,  7,  8],\n",
       "       [10, 12, 14, 16],\n",
       "       [15, 18, 21, 24],\n",
       "       [20, 24, 28, 32]])"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#矩阵外积(只对一维数组计算），matrix_one和matrix_two展平为一维数组[1,2,3,4],[5,6,7,8]\n",
    "#matrix_one每个元素分别与matrix_two一行相乘\n",
    "#[1*5,1*6,1*7,1*8]\n",
    "#[2*5,2*6,2*7,2*8]\n",
    "#[3*5,3*6,3*7,3*8]\n",
    "#[4*5,4*6,4*7,4*8]\n",
    "np.outer(matrix_one,matrix_two)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 48,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[23, 31],\n",
       "       [34, 46]])"
      ]
     },
     "execution_count": 48,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#指定乘积,matrix_onw列乘以matrix_two的行求和\n",
    "#[1*5+3*6].[1*7+3*8]\n",
    "#[2*5+4*6],[2*7+4*8]\n",
    "np.tensordot(matrix_one,matrix_two,axes=[[0],[1]])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.0"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
